package zhongbo.java.air.dictionary.web.controller;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zhongbo.java.air.common.vo.PageVo;
import zhongbo.java.air.common.vo.ResultVo;
import zhongbo.java.air.dictionary.model.AirPort;
import zhongbo.java.air.dictionary.service.IAirPortService;

import java.util.List;

@Api(tags = "机场相关接口")
//@ApiModel("/api/airport")
@RequestMapping("api/airport")
@RestController
public class AirPortController {
    @Autowired
    private IAirPortService airPortService;

    @ApiOperation("增加机场")
    @PostMapping("/addAirPort")
    public ResultVo<String> addAirPort(@RequestBody AirPort airPort) {
        String add = airPortService.addAirPort(airPort);
        if (StrUtil.isNotBlank(add)) { // 如果不为空
            return ResultVo.ok(add);
        }
        return ResultVo.error("新增失败");
    }
    @ApiOperation("查询一个机场")
    @GetMapping("/getAirPort")
    public ResultVo<AirPort> getAirPortById(@RequestParam(defaultValue = "1") String airId) {
        AirPort airPort = airPortService.getAirPortById(airId);
        return ResultVo.ok(airPort);
    }
    @ApiOperation("删除一个机场")
    @DeleteMapping("/deleteAirPort")
    public ResultVo<Integer> deleteAirPort(@RequestParam(defaultValue = "1") String airId) {
        int delete = airPortService.deleteAirPort(airId);
        return ResultVo.ok(delete);
    }
    @ApiOperation("修改一个机场")
    @PutMapping("/updateAirPort")
    public ResultVo<AirPort> updateAirPort(@RequestBody AirPort airPort) {
        AirPort updateAirPort = airPortService.updateAirPort(airPort);
        if (updateAirPort != null) {
            return ResultVo.ok(updateAirPort);
        }
        return null;
    }
    @ApiOperation("查出所有的机场")
    @GetMapping("/AllAirPort")
    public ResultVo<List<AirPort>> getAirPortAll() {
        List<AirPort> airPortList = airPortService.getaAirPortAll();
        return ResultVo.ok(airPortList);
    }
    @ApiOperation("分页查询所有的机场")
    @GetMapping("/pageAirPortAll")
    public ResultVo<PageVo<AirPort>> page(@RequestParam(required = false) String name,
                                          @RequestParam(defaultValue = "1") Integer pageNumber,
                                          @RequestParam(defaultValue = "1") Integer pageSize) {
        PageVo<AirPort> page = airPortService.page(name,pageNumber,pageSize);
        return ResultVo.ok(page);
    }

}
